const mysql = require('mysql')
// let opt = {
//     user:'tarvel',
//     port:3306,
//     password:'ytmx10086',
//     host:'39.103.238.144',
//     database:'tarvel'
// }

let opt = {
    user:'root',
    port:3306,
    password:'',
    host:'127.0.0.1',
    database:'tarvel'
}
const connect = mysql.createPool(opt)

connect.getConnection(err=>{
    if(err) {throw err}
    else{console.log('数据库连接成功！！');}
})


const getMysql = function(sql,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10){
    return new Promise((resolve,reject)=>{
        connect.query(sql,[arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10],(err,data)=>{
            if(err){
                reject(err)
            }else{
                resolve(data)
            }
        })
    })
}

module.exports = getMysql
